<script>
import userApi from "@/api/user_api.js";

export default {
  name: "Login",
  data() {
    return {
      userForm: {
        account: '',
        password: ''
      }
    }
  },
  methods: {
    login() {
      if (this.userForm.account === '' || this.userForm.password === '') {
        return
      }
      userApi.login(this.userForm).then(response => {
          this.$router.push('/home')
      })
    },
    toRegister(){
      this.$router.push('/register');
    }
  }
}
</script>

<template>
  <div class="v-center">
    <h1 style="color: #2c3e50">用户登录</h1>
    <el-form ref="confirmForm"
             label-width="auto" style="max-width: 50vh; margin:0 auto;" size="large">
      <el-form-item label="用户名">
        <el-input v-model="userForm.account" placeholder="请输入用户名"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input  type="password" v-model="userForm.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="">
        <div class="buttonClass">
          <el-button style="width: 20vh" @click="toRegister">注册</el-button>
          <el-button type="primary" style="width: 20vh" @click="login">登录</el-button>
        </div>
      </el-form-item>

    </el-form>
  </div>



</template>

<style scoped>
.buttonClass {
  margin: auto;
}
.v-center{
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  height: 80vh;
}
</style>